//
//  ALVMianTabBarViewController.m
//  Lavoo
//
//  Created by lishen on 2024/3/7.
//

#import "BJTabBarViewController.h"
#import "BJHomeViewController.h"
#import "BJVideoViewController.h"
#import "BJNavigationViewController.h"
#import "BJMineViewController.h"
#import "BJArticleViewController.h"
#import "BJPlayingMethodViewController.h"

#import "BJTabBar.h"

@interface BJTabBarViewController ()

@end

@implementation BJTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self setValue:[BJTabBar new] forKey:@"tabBar"];
    
    
    [self addCustomChildVC:[[BJHomeViewController alloc]init] image:@"ic_home"selectedImage:@"ic_home_selected" title:@""];
    [self addCustomChildVC:[[BJVideoViewController alloc]init] image:@"ic_zone"selectedImage:@"ic_zone_selected" title:@""];
    [self addCustomChildVC:[[BJPlayingMethodViewController alloc]init] image:@"ic_message" selectedImage:@"ic_message_selected" title:@""];
    [self addCustomChildVC:[[BJMineViewController alloc]init] image:@"ic_personal"selectedImage:@"ic_personal_selected" title:@""];
    
}



- (void)addCustomChildVC:(UIViewController *)vc image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
    UIImage *musicImage = [UIImage imageNamed:image];
    UIImage *musicImageSel = [UIImage imageNamed:selectedImage];
    musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.title = title;
 
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:musicImage selectedImage:musicImageSel];

    if (@available(iOS 15.0, *)) {
        UITabBarAppearance *bar = [UITabBarAppearance new];

        bar.backgroundColor = [UIColor whiteColor];

        bar.backgroundEffect = nil;

        bar.stackedLayoutAppearance.selected.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[UIColor redColor]};

        bar.stackedLayoutAppearance.normal.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[UIColor grayColor]};

        self.tabBar.scrollEdgeAppearance = bar;

        self.tabBar.standardAppearance = bar;



    } else {
        self.tabBar.backgroundColor = [UIColor whiteColor];

        self.tabBar.barTintColor = [UIColor whiteColor];

        self.tabBar.translucent = NO;

        [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];

        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];

        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    }
  
    BJNavigationViewController *nav = [[BJNavigationViewController alloc]initWithRootViewController:vc];
    
    [self addChildViewController:nav];
    
}

@end
